<%@page import="java.util.List"%>
<%@page import="common.SerialDAO"%>
<%@page import="common.SerialDTO"%>
<%@page import="approval.ApprovalDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="approval.ApprovalDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	request.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 모바일 사용자를 위해 viewport 추가-->
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<!--모바일 기기에서 확대/축소 불가<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
콘텐츠 중앙으로 가져오기<div class="container">...</div>-->
<title></title>
<!-- bootstrap -->
<link rel="stylesheet"
	href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/intranet/css/bootstrap.css">
<!-- DateTimePicker -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/intranet/css/jquery.datetimepicker.css" />
<script src="${pageContext.request.contextPath }/intranet/js/jquery.datetimepicker.js"></script>
<script>
	jQuery(function() {
		$("#srchDetail").hide();
		$('.selectpicker').selectpicker({
			"width" : "100px"
		});
		
		jQuery('#date_timepicker_start').datetimepicker(
				{
					format : 'Y/m/d',
					onShow : function(ct) {
						this
								.setOptions({
									maxDate : jQuery('#date_timepicker_end')
											.val() ? jQuery(
											'#date_timepicker_end').val()
											: false
								});
					},
					timepicker : false
				});
		jQuery('#date_timepicker_end').datetimepicker(
				{
					format : 'Y/m/d',
					onShow : function(ct) {
						this
								.setOptions({
									minDate : jQuery('#date_timepicker_start')
											.val() ? jQuery(
											'#date_timepicker_start').val()
											: false
								});
					},
					timepicker : false
				});
	});
	function srchToggle() {
		//alert("고급검색눌렀냥");
		$("#srchDetail").slideToggle("slow");
	}
	function btnApNoSrch() {
		// 결재번호로 검색하기
		var find = $("#apnoSrch").val(); // 결재번호단건조회
		if(find == null || find == ''){
			alert("검색어를 입력해주세요.");
			return;
		}
		/* var nowPage = $("#nowPage").val(); */
		//alert(srchTxt);
		var url = "${pageContext.request.contextPath}/intranet/approval/ap_srch.jsp";
		var params = "find=" + find /* + "&nowPage=" + nowPage */;
		//alert(url+"?find="+find);
		$.ajax({
			  type: 'POST'
			, url : url
			, data : params
			, success: function(testList){
				//alert(testList);
	        	$('#tableDiv').html(testList);
				//initialize();
				//$('#tb_cdList').load("${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_list_crud.jsp #tb_cdList");
			}
			, error:function(request,status,error){
	            alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
	        }
		});
		
	}
	function btnDetailSrch() {
		//alert("상세조건으로 검색합니다.");
		var saNm = $("#saNm").val(); // 사원명
		var ctno = $("#ctno").val(); // 계약번호
		var ct_ing = $("#ct_ing option:selected").val(); // 상태
		var ap_sdt = $("#date_timepicker_start").val(); // 시작일
		var ap_edt = $("#date_timepicker_end").val(); // 종료일
		var sa_reporter = $("#sa_reporter").val(); // 상신자
		var sa_decider = $("#sa_decider").val(); // 승인자
		/* var nowPage = $("#nowPage").val(); // nowPage */
		
		if(saNm == "" && ctno == "" && (ct_ing == '' || ct_ing == '상태') && ap_sdt == '' && ap_edt == '' && sa_reporter == '' && sa_decider == ''){
			alert("검색 조건을 설정해주세요.");
			return;
		}
		
		/* var str = "";
		if(saNm != null){str += saNm}
		if(ctno != null){str += ctno}
		if(ct_ing != null && ct_ing != "상태"){str += ct_ing}
		if(date_start != null){str += date_start}
		if(date_end != null){str += date_end}
		if(sa_reporter != null){str += sa_reporter}
		if(sa_decider != null){str += sa_decider} */
		var url = "${pageContext.request.contextPath}/intranet/approval/ap_srch.jsp";
		var params = "sa_no_nm=" + saNm;
		    params = params + "&ct_no=" + ctno;
		if(ct_ing != null && ct_ing != "상태"){
			params = params + "&ct_ing_nm=" + ct_ing;
		}
		params = params + "&ap_sdt=" + ap_sdt;
		params = params + "&ap_edt=" + ap_edt;
		params = params + "&ap_req_sa_nm=" + sa_reporter;
		params = params + "&ap_ap_sa_nm=" + sa_decider;
		/* params = params + "&nowPage=" + nowPage; */
		//alert(params);
		 $.ajax({
			  type: 'POST'
			, url : url
			, data : params
			, success: function(testList){
				//alert(testList);
	        	$('#tableDiv').html(testList);
				//initialize();
				//$('#tb_cdList').load("${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_list_crud.jsp #tb_cdList");
			}
			, error:function(request,status,error){
	            alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
	        }
		});
	}
	function openViewWindow(ap_no, gubun) {
		window.open("../intranet/approval/ap_popup.jsp?ap_no="+ap_no+"&gubun="+gubun, "_blank", "resizable=yes, top=100, left=200, width=630, height=530");
	}
	
</script>
</head>
<body>
<jsp:useBean id="dto" class="approval.ApprovalDTO" />
<jsp:setProperty property="*" name="dto"/>
<%

SerialDTO sdto = new SerialDTO("APPROVAL","AP_NO","A");
SerialDAO sdao = new SerialDAO();
sdao.setDto(sdto);
String serial = sdao.serialReturn();
System.out.print(serial);
ApprovalDAO dao = new ApprovalDAO();
dao.setDto(dto);

/* nowPage 셋팅 ================== */
/* dao.setNowPage(dto.getNowPage()); */
/* =============================== */

List<ApprovalDTO> ap = dao.list();

%>
	<!-- 제목 -->
	<h1 style="text-align: center;">
		결재 목록<small>Approval List</small>
	</h1>

	<!-- // 검색된 데이터 총 갯수 -->
<%-- <div>
<ul>
<li>전체건수 : <%=dao.getTotSize() %></li>
<li>전체페이지수 : <%=dao.getTotPage() %></li>
<li>전체블럭수 : <%=dao.getTotBlock() %></li>
<li>현재블럭수 : <%=dao.getNowBlock() %></li>
<li>시작페이지 : <%=dao.getStartPage() %></li>
<li>현재페이지 : <%=dao.getNowPage() %></li>
<li>끝페이지 : <%=dao.getEndPage() %></li>
<li>시작번호 : <%=dao.getStartNo() %></li>
<li>끝번호 : <%=dao.getEndNo() %></li>
</ul>
</div>  --%>
<%-- <input type="hidden" id="nowPage" value="<%=dao.getNowPage() %>"> --%>
	<!-- 검색 고급 검색 영역 -->
	<div class="row" style="margin: 20px 0px 0px 1050px;">
		<div class="col-md-9">

			<div class="row">
				<div class="col-md-6">
					<div class="row">
						<div class="col-md-6" style="margin-left: -55px;">
							<div class="input-group" style="width: 320px;">
								<input type="search" id="apnoSrch" class="form-control" placeholder="결재번호">
								<span class="input-group-btn">
									<button class="btn btn-primary" type="button"
										onclick="btnApNoSrch()">
										<span class="glyphicon glyphicon-search">&nbsp;</span>검색
									</button>
									<button id="btnSrchDetail" class="btn btn-info" type="button"
										onclick="srchToggle()">고급검색</button>
								</span>
							</div>
							<!-- /input-group -->
							<br />
						</div>
						<!-- /.col-lg-6 -->
					</div>
					<!-- /.row -->
				</div>
			</div>


		</div>
	</div>

	<!-- 상세 검색 영역 -->
	<form class="form-inline" role="form" id="srchDetail"
		style="text-align: center; margin-left: 400px;">
		<div class="form-group" style="width: 100px;">
			<input type="text" class="form-control" id="saNm"
				placeholder="사원명">
		</div>
		<div class="form-group" style="width: 100px;">
			<input type="text" class="form-control"
				id="ctno" placeholder="계약번호">
		</div>
		<div class="form-group">

			<select class="selectpicker" id="ct_ing">
				<option selected="selected"><b>상태</b></option>
				<option>상담완료</option>
				<option>결재대기</option>
				<option>결재승인</option>
				<option>결재부결</option>
				<option>결재반려</option>
			</select>
		</div>
		
		<div class="form-group" style="width: 100px;">
			<input id="date_timepicker_start" class="form-control" type="text"
				placeholder="시작일" />
		</div>
		<div class="form-group" style="width: 100px;">
			<input id="date_timepicker_end" class="form-control" type="text"
				placeholder="종료일" />
		</div>
		
		<!-- DatePicker 부분 -->
		<script type="text/javascript">
			// <![CDATA[
			jQuery(function() {
				jQuery('#date_timepicker_start').datetimepicker(
						{
							format : 'Y/m/d',
							onShow : function(ct) {
								this.setOptions({
									maxDate : jQuery('#date_timepicker_end')
											.val() ? jQuery(
											'#date_timepicker_end').val()
											: false
								});
							},
							timepicker : false
						});
				jQuery('#date_timepicker_end').datetimepicker(
						{
							format : 'Y/m/d',
							onShow : function(ct) {
								this.setOptions({
									minDate : jQuery('#date_timepicker_start')
											.val() ? jQuery(
											'#date_timepicker_start').val()
											: false
								});
							},
							timepicker : false
						});
			});
			// ]]>
		</script>

		<div class="form-group" style="width: 100px;">
			<input type="text" class="form-control" id="sa_reporter" placeholder="상신자명">
		</div>
		<div class="form-group" style="width: 100px;">
			<input type="text" class="form-control" id="sa_decider" placeholder="승인자명">
		</div>
		<div class="form-group">
			<button type="button" data-loading-text="검색중..."
				class="btn btn-success" onclick="btnDetailSrch()">
				<span class="glyphicon glyphicon-search">&nbsp;</span>검색
			</button>
		</div>
	</form>
	<p/><br/>
	<!-- 테이블 영역 -->
	<table class="table"
		style="width: 1200px; margin: 0 auto;" id="tableDiv">
		<thead style="background-color: #e5e5e5;">
			<tr>
				<th>결재번호</th>
				<th>계약번호</th>
				<th>사원명</th>
				<th>상태</th>
				<th>신청일자</th>
				<th>상신자</th>
				<!-- <th>승인자</th> -->
				<!-- <th>등록자</th> -->
				<th>등록일</th>
				<th>수정자</th>
				<th>수정일</th>
			</tr>
		</thead>
		<tbody align="center">
			<tr>
			<%
			if(ap == null) return;
			if(ap.size() == 0){%>
				<td>금일 등록된 결재건이 없습니다. :)</td>
			<%}else{
			for(int i=0; i<ap.size(); i++){
				ApprovalDTO gun = ap.get(i);
			%>
				<td><a href="#" onclick="openViewWindow('<%=gun.getAp_no() %>', 'ap_list')"><%=gun.getAp_no() %></a></td>
				<td><%=gun.getCt_no() %></td>
				<td><%=gun.getSa_no_nm() %></td>
				<td><%=gun.getCt_ing_nm() %></td>
				<td><%=gun.getAp_req_time() %></td>
				<td><%=gun.getAp_req_sa_nm() %></td>
				<%-- <td><%=gun.getAp_ap_sa_nm() %></td> --%>
				<%-- <td><%=gun.getRg_pp_nm() %></td> --%>
				<td><%=gun.getRg_dt() %></td>
				<td><%=gun.getMd_pp_nm() %></td>
				<td><%=gun.getMd_dt() %></td>
			</tr>
			<%} }%>
		</tbody>
	</table>
</body>

</html>